<?php
/**附件表视图模型
 * @Author: 976123967@qq.com
 * @Date:   2014-09-21 21:54:09
 * @Last Modified by:   chen
 * @Last Modified time: 2014-09-21 22:37:23
 */
class UploadViewModel extends ViewModel{


	protected $tableName = 'upload';

	public $viewFields = array(
	
		'upload'=>array(
			'*',
			'_type'=>'INNER',
		),
		'user'=>array(
			'username',
			'_type'=>'INNER',
			'_on'=>'upload.user_uid=user.uid'
		),

	);




	/**
	 * [get_upload_all 所有附件信息]
	 * @return [type] [description]
	 */
	public function get_upload_all()
	{
		$count = $this->count();
		import('ORG.Util.Page');// 导入分页类
		$page = new Page($count,$count);
		$data = $this->order('addtime desc')->limit($page->firstRow.','.$page->listRows)->select();
		if(!$data) return $data;
		foreach($data as $k=>$v)
		{
			// 大小
			$data[$k]['size'] = get_size($v['size']);
			//时间
			$data[$k]['time'] = date('Y-m-d',$v['addtime']);

			// 图片
			$file = $v['path'].'/'.$v['name'].'.'.$v['ext'];
			$data[$k]['ispic'] = $ispic =getimagesize($file);
			$data[$k]['img'] = $ispic?__ROOT__.'/'.$file:__ROOT__.'/Data/Image/default.gif';

		}
		$data['page'] = $page->show();
		return $data;

	}
}